﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using Intel_Client_GUI.ServiceReference1;

namespace Intel_Client_GUI
{
    class ImageConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int uuid;
            if (!int.TryParse(value.ToString(),out uuid))
                return null;
            var Client = new ServiceReference1.PluginServerClient();
            var bitSource = new BitmapImage();
            bitSource.BeginInit();
            bitSource.StreamSource = Client.GetPic(uuid);
            bitSource.EndInit();
            return bitSource;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
        #endregion
    }
    class DownloadButtonCheck : IValueConverter
    {

        #region IValueConverter 成员
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var p = value as PluginInfo;
            if (p != null)
                return !Globle.Pm.Contains(p.Uuid);
            return true;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
        #endregion
    }
    class DownloadTextConverter : IValueConverter
    {

        #region IValueConverter 成员
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var p = value as PluginInfo;
            if (p != null)
                if(Globle.Pm.Contains(p.Uuid))
                    return "Installed";
            return "Download";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
        #endregion
    }
}
